package com.fancy.middleware.netty.config;

import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@ConditionalOnExpression(value = "T(io.netty.util.internal.PlatformDependent).isWindows()")
public class NioNettyConfiguration {

    @Bean("bossEventLoopGroup")
    @ConditionalOnMissingBean(name = "bossEventLoopGroup")
    public EventLoopGroup bossEventLoopGroup(){
        return new NioEventLoopGroup();
    }

    @Bean("workerEventLoopGroup")
    @ConditionalOnMissingBean(name = "workerEventLoopGroup")
    public EventLoopGroup workerEventLoopGroup(){
        return new NioEventLoopGroup();
    }

    @ConditionalOnMissingBean
    @Bean
    public Class channel() {
        return NioServerSocketChannel.class;
    }


}
